package com.xique.park.controller.client.web.controller;

import com.xique.common.core.domain.R;
import com.xique.common.core.utils.poi.ExcelUtil;
import com.xique.common.core.web.controller.BaseController;
import com.xique.common.core.web.domain.AjaxResult;
import com.xique.common.core.web.page.TableDataInfo;
import com.xique.common.log.annotation.Log;
import com.xique.common.log.enums.BusinessType;
import com.xique.common.security.annotation.PreAuthorize;
import com.xique.park.controller.client.web.bean.domain.ClientLoginInfo;
import com.xique.park.controller.client.web.service.biz.service.IClientLoginInfoBizService;
import com.xique.park.controller.client.web.service.service.IClientLoginInfoService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 系统访问记录Controller
 *
 * @author shd
 * @date 2021-07-22
 */
@RestController
@RequestMapping("/loginInfo")
public class ClientLoginInfoController extends BaseController
{
    @Autowired
    private IClientLoginInfoService clientLoginInfoService;

    @Autowired
    private IClientLoginInfoBizService clientLoginInfoBizService;

    /**
     * 查询系统访问记录列表
     */
    @PreAuthorize(hasPermi = "oms:ClientLoginInfo:list")
    @GetMapping("/list")
    public TableDataInfo list(ClientLoginInfo clientLoginInfo)
    {
        startPage();
        List<ClientLoginInfo> list = clientLoginInfoService.selectClientLoginInfoList(clientLoginInfo);
        return getDataTable(list);
    }

    /**
     * 导出系统访问记录列表
     */
    @PreAuthorize(hasPermi = "oms:ClientLoginInfo:export")
    @Log(title = "系统访问记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ClientLoginInfo clientLoginInfo) throws IOException
    {
        List<ClientLoginInfo> list = clientLoginInfoService.selectClientLoginInfoList(clientLoginInfo);
        ExcelUtil<ClientLoginInfo> util = new ExcelUtil<ClientLoginInfo>(ClientLoginInfo.class);
        util.exportExcel(response, list, "系统访问记录数据");
    }

    /**
     * 获取系统访问记录详细信息
     */
    @PreAuthorize(hasPermi = "oms:ClientLoginInfo:query")
    @GetMapping(value = "/{infoId}")
    public AjaxResult getInfo(@PathVariable("infoId") Long infoId)
    {
        return AjaxResult.success(clientLoginInfoService.selectClientLoginInfoById(infoId));
    }

    /**
     * 新增系统访问记录
     */
//    @PreAuthorize(hasPermi = "oms:ClientLoginInfo:add")
    @Log(title = "系统访问记录", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增系统访问记录")
    public R<Boolean> add(Long clientId, String username, String status, String message)
    {
        return clientLoginInfoBizService.addLoginInfo(clientId, username, status, message);
    }

    /**
     * 修改系统访问记录
     */
    @PreAuthorize(hasPermi = "oms:ClientLoginInfo:edit")
    @Log(title = "系统访问记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ClientLoginInfo clientLoginInfo)
    {
        return toAjax(clientLoginInfoService.updateClientLoginInfo(clientLoginInfo));
    }

    /**
     * 删除系统访问记录
     */
    @PreAuthorize(hasPermi = "oms:ClientLoginInfo:remove")
    @Log(title = "系统访问记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{infoIds}")
    public AjaxResult remove(@PathVariable Long[] infoIds)
    {
        return toAjax(clientLoginInfoService.deleteClientLoginInfoByIds(infoIds));
    }
}
